﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartSpace.Workflow
{
    public interface IWorkflowService
    {
        ServiceResult SaveWorkflow(WorkflowMetadata workflow);
        ServiceResult SaveActivity(ActivityMetadata activity);
        ServiceResult SaveEvent(EventMetadata @event);
        SingleResult<WorkflowMetadata> GetWorkflow(Guid workflowId);
        SingleResult<WorkflowMetadata> GetWorkflow(string workflowCode);
        SingleResult<ActivityMetadata> GetActivity(Guid activityId);
        SingleResult<EventMetadata> GetEvent(Guid eventId);

        ListResult<WorkflowMetadata> GetWorkflows();

        ListResult<ActivityMetadata> GetActivities(Guid workflowId);
        List<ActivityMetadata> GetActivities(string refModule);

        ListResult<EventMetadata> GetEvents(Guid activityId);

        /// <summary>
        /// 创建流程实例,返回流程的状态信息
        /// </summary>
        /// <param name="refModule"></param>
        /// <param name="refId"></param>
        /// <param name="caption"></param>
        /// <param name="creator"></param>
        /// <returns></returns>
        SingleResult<InstanceState> CreateInstance(string refModule, Guid refId, string caption, string creator);
        /// <summary>
        /// 驱动流程继续执行
        /// </summary>
        /// <param name="instanceId">流程实例编号</param>
        /// <param name="eventId">事件编号</param>
        /// <param name="refId">数据编号</param>
        /// <param name="refModule">业务模块</param>
        /// <param name="operator">操作员</param>
        /// <param name="receivers">下一步接收人</param>
        /// <returns></returns>
        SingleResult<InstanceState> DriveInstance(Guid instanceId, Guid eventId, Guid refId, string refModule, string @operator, List<string> receivers);
        SingleResult<WorkflowInstance> GetInstance(string refModule, Guid refId);
        PagedResult<WorkflowInstance> GetInstances(string module, int start, int limit);
        /// <summary>
        /// 获取流程实例当前的状态
        /// </summary>
        /// <param name="refModule"></param>
        /// <param name="refId"></param>
        /// <returns></returns>
        SingleResult<InstanceState> GetInstanceState(string refModule, Guid refId);

        ListResult<WorkflowTask> GetTasks(string user);

        /// <summary>
        /// 获得当前数据的流程活动步骤
        /// </summary>
        /// <param name="dataModule"></param>
        /// <param name="dataId"></param>
        /// <returns></returns>
        ListResult<WorkflowStep> GetActiveSteps(string dataModule, Guid dataId);
    }
}
